package lsystem;

import java.util.ArrayList;
import java.util.Stack;

import symbol.LSymbol;
import turtle3d.Turtle3D;


public class LTurtleMaster {
	private Turtle3D turtle3D;
	private ArrayList<LVisualSymbol> visualSequence = new ArrayList<LVisualSymbol>();
	
	private float angle = 45;

	public LTurtleMaster(Turtle3D turtle3D) {
		super();
		this.turtle3D = turtle3D;
	}
	
	public void interpretLSymbol(LSymbol symbol){								
		
		LVisualSymbol visualSymbol = new LVisualSymbol(symbol, turtle3D.getTransformMatrix(), turtle3D.getDepth());
		visualSequence.add(visualSymbol);
		
		String s = symbol.getSymbol(); 
		if(s.equals("F")){
			turtle3D.forward(0.2f);					
		}
		else if(s.equals("+")){
			turtle3D.turn(-angle);
		}
		else if(s.equals("-")){
			turtle3D.turn(angle);
		}
		else if(s.equals("[")){
			turtle3D.push();			
		}
		else if(s.equals("]")){
			turtle3D.pop();
		}
		else if(s.equals("<")){
			turtle3D.roll(-90);
		}
		else if(s.equals(">")){
			turtle3D.roll(90);
		}				
		
	}
	
	public void interpretLSymbols(ArrayList<LSymbol> symbols){
		for(LSymbol s:symbols){
			interpretLSymbol(s);
		}
		
		visualSequence.add(new LVisualSymbol(symbols.get(symbols.size()-1), turtle3D.getTransformMatrix()));
	}

	public ArrayList<LVisualSymbol> getVisualSequence()
	{
		return visualSequence;
	}

	public float getAngle()
	{
		return angle;
	}

	public void setAngle(float angle)
	{
		this.angle = angle;
	}
}
